<template>
  <div class="search-history">
    <van-cell title="搜索历史">
      <div v-if="isDeleteShow">
        <span @click="$emit('clear-all-search-history')">全部删除</span>
        &nbsp;&nbsp;&nbsp;
        <span @click="isDeleteShow = false" >完成</span>
      </div>
      <van-icon v-else name="delete" @click="isDeleteShow = true"/>
    </van-cell>
    <van-cell
      :title="item"
      v-for="(item, index) in searchHistoryData"
      :key="index"
      @click="onDeleteHistory(item, index)"
    >
      <van-icon name="close" v-show="isDeleteShow"/>
    </van-cell>
  </div>
</template>

<script>
export default {
  name: 'SearchHistory',
  props: {
    searchHistoryData: {
      type: Array,
      required: true
    }
  },
  data () {
    return {
      // 控制删除显示状态
      isDeleteShow: false
    }
  },
  methods: {
    onDeleteHistory (item, index) {
      if (this.isDeleteShow) {
        this.$emit('deleteHistory', index)
      } else {
        this.$emit('searchHistory', item)
      }
    }
  }
}
</script>

<style lang="less" scoped>

</style>
